﻿@{
    ViewBag.Title = "用户列表";
    Layout = "~/Views/Shared/_Main.cshtml";
}
@section Head{
    <style type="text/css">
        .pagTable
        {
            width: 100%;
            border-left: solid 1px #ccc;
            table-layout: fixed;
        }
        .pagTable td
        {
            height: 25px;
            border-right: 1px solid #ccc;
            border-bottom: 1px solid #ccc;
            padding-right: 3px;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }
    </style>
    <script type="text/javascript">
        
        var opts = {
            rows: 10,
            height: 450,
            url: "",
            para: {},
            idField: "Guid",
            checkbox: false,
            columns: [
                     { field: 'EmployeeCode', title: '工号', width: 8, sortable: true },
                     { field: 'EmployeeName', title: '姓名', width: 15, sortable: true },
                     { field: 'Username', title: '用户名', width: 15, sortable: true },
                     { field: 'CompanyName', title: '公司', width: 35, sortable: true },
                     { field: 'Gender', title: '性别', align: 'center', width: 5, align: 'center',
                         formatter: function (value, rowData, rowIndex) {
                             if (value == 1)
                                 return "男";
                             if (value == 2)
                                 return "女";
                         }
                     },

                     { field: 'Status', title: '状态', align: 'center', width: 6,
                         formatter: function (value, rowData, rowIndex) {
                             if (value == 1)
                                 return "启用";
                             if (value == 2)
                                 return "<span class='grid_r'>禁用</span>";
                         }
                     },
                     { field: 'UserType', title: '用户类型', align: 'center', width: 6,
                         formatter: function (value, rowData, rowIndex) {
                             if (value == 1)
                                 return "录入";
                             if (value == 2)
                                 return "导入";
                         }
                     },
                     { field: 'Guid', title: '操作', width: 10, sortable: false,
                         formatter: function (value, rowData, rowIndex) {
                             var doActionOptions = "<select onchange='return DoAction(this.options.selectedIndex,\"" + value + "\")' style='width: 100px; '> <option value=''>-请选择-</option>";

                             var format = doActionOptions;
                             if (rowData.Status == 1) {
                                 format += "<option >禁用</option>"
                             }
                             else {
                                 format += "<option >启用</option>"
                             }
                             format += "<option >查看</option>"
                             if (rowData.UserType == "1") {
                                 format += "<option >修改</option>"
                                 format += "<option >删除</option>"
                             }


                             format += "</select>";
                             return format;
                         }
                     }
                    ]

        };

        $(function () {
            page_Init();
            InitList();
        });

        function page_Init() {
            $("body").css("overflow", "hidden");
        }
        function btnSearch_Click() {
            var company = $("#txt_Company").val();
            var department = $("#txt_Department").val();
            var post = $("#txt_Post").val();
            var employeeName = $("#txt_EmployeeName").val();
            var userName = $("#txt_UserName").val();
            var userType = $("#ddl_UserType").val();

            var postUrl = "/SysUser/GetList/?Company=" + encodeURI(company)
            + "&Department=" + encodeURI(department)
            + "&Post=" + encodeURI(post)
            + "&EmployeeName=" + encodeURI(employeeName)
            + "&UserName=" + encodeURI(userName)
            + "&UserType=" + encodeURI(userType);
            InitList(postUrl);
        }
        function btnAdd_Click() {
            AddUser();
        }
        function InitList(postUrl) {

            if (typeof (postUrl) == "undefined" || postUrl.length == 0) {
                postUrl = "/SysUser/GetList";
            }
            opts.url = postUrl;
            $("#DataGrid").dg(opts);
        }
        //“操作”下拉框事件
        function DoAction(i, value) {
            if (i == 1) {
                // 启用/禁用
                UpdateState(value);
            }
            else if (i == 2) {
                // 查看
                ReadUser(value);
            }
            else if (i == 3) {
                // 编辑
                EditUser(value);
            }
            else if (i == 4) {
                // 删除
                DeleteUser(value);
            }
            InitList();
        }
        function ReadUser(userID) {
            //window.location.href = "/SysUser/Read";
            var url = "/SysUser/Read?userID=" + userID;
            showModalMany('TaskStatus', url, '600', '365',
                            function (result) {
                            });
            //btnSearch_Click();
        }
        function AddUser() {
            //window.location.href = "/SysUser/Edit";
            var url = "/SysUser/Edit";
            showModalMany('TaskStatus', url, '600', '365',
                            function (result) {
                                //btnSearch_Click();
                            });
            btnSearch_Click();
        }
        function EditUser(userID) {
            //window.location.href = "/SysUser/Edit?userID=" + userID;
            var url = "/SysUser/Edit?userID=" + userID;
            showModalMany('TaskStatus', url, '700', '500',
                            function (result) {
                                //btnSearch_Click();
                            });
            btnSearch_Click();
        }
        function DeleteUser(userID) {
            if (confirm("确定要删除吗?")) {
                $.post("/SysUser/DeleteRole?userID=" + userID, function (result) {
                    if (result.Success == true) {
                        alert(result.Message);
                    }
                    else {
                        alert(result.Message);
                    }
                    InitList();
                });
            }
        }
        function UpdateState(userID) {
            if (confirm("确定要更改状态吗?")) {
                $.post("/SysUser/UpdateState?userID=" + userID, function (result) {
                    if (result.Success == true) {
                        alert(result.Message);
                    }
                    else {
                        alert(result.Message);
                    }
                    InitList();
                });
            }
        }
    </script>
}
<div style="margin: 5px;">
    @{
        // 渲染输出列表
        var dataSearch = new ViewDataDictionary();
        dataSearch.Add("PanelTitle", "用户搜索");
        @Html.Partial("_SearchTitlePanel", dataSearch);
        //Html.RenderPartial("_SearchTitlePanel", dataSearch);
    }
    @Html.Partial("_SearchUserPanel")
</div>
<div style="margin: 5px; min-height: 300px;">
    @{
        // 渲染输出列表
        var dataGrid = new ViewDataDictionary();
        dataGrid.Add("PanelTitle", "用户列表");
        dataGrid.Add("GridID", "DataGrid");
        dataGrid.Add("ShowAddButton", true);
        dataGrid.Add("ShowDeleteButton", false);
        dataGrid.Add("ShowOtherButton", false);
        dataGrid.Add("ShowBackButton", false);
        dataGrid.Add("ShowCloseButton", false);
        dataGrid.Add("ShowPager", true);
        dataGrid.Add("ShowLoading", true);
        @Html.Partial("_GridPanel", dataGrid);
    }
</div>
